package com.huaxiafinance.management.controller;


import com.huaxiafinance.management.dto.request.QuerySignRecordDto;
import com.huaxiafinance.management.model.UserSignRecord;
import com.huaxiafinance.management.service.UserSignRecordService;
import com.huaxiafinance.management.util.MessageResult;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;


/**
 * 签到记录管理控制器
 */
@Controller("userSignRecordController")
@RequestMapping("/userSignRecord")
public class UserSignRecordController {

  private static final Logger logger = Logger.getLogger(UserSignRecordController.class);

  @SuppressWarnings("SpringJavaAutowiringInspection")
  @Autowired
  private UserSignRecordService userSignRecordService;

  /**
   * 按指定条件查询签到记录
   */
  @RequestMapping(value = "/query", produces = "application/json; charset=utf-8")
  public @ResponseBody
  String querySignFlow(@Valid @ModelAttribute("dto") QuerySignRecordDto dto) {
    logger.info("查询签到记录请求参数=================================>" + dto);
    MessageResult messageResult = new MessageResult();
    if (dto.getEnd() == null || dto.getStart() == null) {
      messageResult.setRows(0);
      messageResult.setSuccessResult();
      messageResult.setData(new ArrayList());
      return messageResult.getAsJSON();
    }
    List<UserSignRecord> list = userSignRecordService.selectSignRecordList(dto);
    int rows = userSignRecordService.countSignRecord(dto);
    messageResult.setRows(rows);
    messageResult.setSuccessResult();
    messageResult.setData(list);
    logger.info("查询签到记录返回参数=================================>" + messageResult.getAsJSON());
    return messageResult.getAsJSON();
  }

}
